<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page import="java.util.*"%>
<%@ page import="qna.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<!-- 게시물 수 -->
<%!static int QNA_PAGE_SIZE = 5;%>

<!--  -->
<%
	String qna_gs_code = request.getParameter("GS_CODE");	
//	String gsCode = request.getParameter("GS_CODE");
	String qna_pageNum = request.getParameter("page");
	if (qna_pageNum == null || qna_pageNum == "") qna_pageNum = "1";
	int qna_currentPage = Integer.parseInt(qna_pageNum);
	QnaWritingManager qnaManager = QnaWritingManager.getInstance();
	
	int qna_count = qnaManager.count(0, qna_gs_code);
	int qna_totalPageCount = 0;
	int qna_startRow = 0, qna_endRow = 0;
	if (qna_count > 0) {
		qna_totalPageCount = qna_count / QNA_PAGE_SIZE;
		if (qna_count % QNA_PAGE_SIZE > 0) qna_totalPageCount++;
		qna_startRow = (qna_currentPage - 1) * QNA_PAGE_SIZE;
		qna_endRow = qna_currentPage * QNA_PAGE_SIZE;
	}	
	List<QnaWriting> qna_list = qnaManager.selectList(qna_startRow, QNA_PAGE_SIZE, 0, qna_gs_code);
%>

<!--  -->
<c:set var="qna_list" value="<%=qna_list%>" />
<c:set var="GS_CODE" value="<%=qna_gs_code%>" />

<!-- 상단제목 -->
<table width="900" align=center cellpadding=0 cellspacing=0>
	<tr>
		<td>
			<div
				style="border:1px solid #ddd; height:34px; background:url(${WEB_ROOT }/img/bbs/title_bg.gif) repeat-x;">
				<div style="font-weight: bold; font-size: 14px; margin: 7px 0 0 10px;" align="center">
					::&nbsp;&nbsp;상품 문의 게시판&nbsp;&nbsp;::</div>
			</div>
		</td>
	</tr>
</table>
<p>
<!--  -->
<table width="900" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td>
			<table cellspacing="0" cellpadding="0" class="board_list">
				<col width="50" />
				<col />
				<col width="110" />
				<col width="110" />
				<col width="50" />

				<tr>
					<th>번호</th>
					<th>제목</th>
					<th>글쓴이</th>
					<th>날짜</th>
					<th>조회</th>
				</tr>

				<c:if test="${empty qna_list }">
					<tr>
						<td bgcolor="#f0f0f0" colspan="5" height="100" align="center">게시물이 없습니다.</td>
					</tr>
				</c:if>

				<c:if test="${!empty qna_list }">
					<c:forEach var="qna_writing" items="${qna_list }">
						<tr bgcolor="#f0f0f0">
							<c:set var="bgChk" value="${ (cnt % 2) == 0 ? 0 : 1 }" />
						<tr class="bg${bgChk }">

							<!--리스트 시작-->
							<td class="num">${qna_writing.writing_id }</td>
							<td class="subject">
							<c:forEach var="cnt" begin="0" end="${qna_writing.level_id }">&nbsp; &nbsp;</c:forEach>
							<a href="javascript:go_Qna_View(${qna_writing.writing_id })">${qna_writing.bbs_title}</a></td>
							<td class="name">${qna_writing.mb_name }</td>
							<td class="datetime">${qna_writing.bbs_date }</td>
							<td class="hit">${qna_writing.bbs_view_cnt }</td>
							<!--리스트 종료-->

						</tr>
					</c:forEach>
				</c:if>

				<tr>
					<td colspan='5' height=25 align=center>
						<div class="board_page">

							<!--페이지 번호 시작-->
							<c:set var="qna_count" value="<%=Integer.toString(qna_count)%>" />
							<c:set var="qna_PAGE_SIZE" value="<%=Integer.toString(QNA_PAGE_SIZE)%>" />
							<c:set var="qna_currentPage" value="<%=Integer.toString(qna_currentPage)%>" />
							<c:if test="${qna_count > 0 }">

								<c:set var="qna_pageCount"
									value="${qna_count / qna_PAGE_SIZE + (qna_count % qna_PAGE_SIZE == 0 ? 0 : 1) }" />
								<c:set var="qna_startPage"
									value="${qna_currentPage - (qna_currentPage % 10 == 0 ? 10:(qna_currentPage % 10)) + 1 }" />
								<c:set var="qna_endPage" value="${qna_startPage + 9 }" />
								<c:if test="${qna_endPage > qna_pageCount }">
									<c:set var="qna_endPage" value="${qna_pageCount }" />
								</c:if>
								
								<!-- 처음버튼 -->
								<c:if test="${qna_startPage > 1  }">
									<a href="javascript:go_Qna_Page(${qna_startPage})"> <img
										src='${WEB_ROOT }/img/bbs/page_begin.gif' border='0'
										align='absmiddle' title='처음'>&nbsp;
									</a>
								</c:if>
								
								<!-- 이전버튼 -->
								<c:if test="${qna_startPage > 10  }">
									<a href="javascript:go_Qna_Page(${qna_startPage-10 })"> <img
										src='${WEB_ROOT }/img/bbs/page_prev.gif' border='0'
										align='absmiddle' title='이전'>&nbsp;
									</a>
								</c:if>

								<!-- 숫자표시 -->
								<c:forEach var="pageNo" begin="${qna_startPage }" end="${qna_endPage }">
									<c:if test="${qna_currentPage == pageNo }">
										<font size="4">
									</c:if>
									<a href="javascript:go_Qna_Page(${pageNo })">${pageNo }&nbsp;</a>
									<c:if test="${qna_currentPage == pageNo }">
										</font>
									</c:if>
								</c:forEach>

								<!-- 다음버튼 -->
								<c:if test="${qna_endPage < qna_pageCount  }">
									<a href="javascript:go_Qna_Page(${qna_startPage+10 })"> <img
										src='${WEB_ROOT }/img/bbs/page_next.gif' border='0'
										align='absmiddle' title='다음'>&nbsp;
									</a>
								</c:if>

								<!-- 맨끝버튼 -->
								<c:if test="${qna_startPage > 1  }">
									<a href="javascript:go_Qna_Page(<fmt:formatNumber value="${qna_endPage}" pattern="#"/>)"> <img
										src='${WEB_ROOT }/img/bbs/page_end.gif' border='0'
										align='absmiddle' title='맨끝'></a>
								</c:if>
							</c:if>
							<!--페이지 번호 종료-->

						</div>
					</td>
				</tr>
				<tr>
					<!-- 전체게시물수 표시 -->
					<td colspan="3" height=25 align="left"><%=qna_count%> 개의 게시글이
						있습니다.</td>

					<!-- 글쓰기 버튼 -->
					<td colspan="2" height=25 align=right>
					<c:if test="${sessionScope.SESSION_MB_NO != null }">
					<a href="${WEB_ROOT }/qna/goodsQnaWrite.jsp?GS_CODE=${GS_CODE }">
						<img src="${WEB_ROOT }/img/bbs/btn_write.gif" border='0'></a></c:if></td>
				</tr>
			</table>
		</td>
	</tr>
</table>

<!--  -->
<script language="JavaScript">
	function go_Qna_Page(pageNo) {
		document.qna_move.action = "${WEB_ROOT }/goods/goodsView.jsp";
		document.qna_move.page.value = pageNo;
		document.qna_move.submit();
	}

	function go_Qna_View(id) {
		document.qna_move.action = "${WEB_ROOT }/qna/goodsQnaView.jsp";
		document.qna_move.id.value = id;
		document.qna_move.submit();
	}
</script>

<!-- -->
<form name="qna_move" method="post">
	<input type="hidden" name="id" value="" /> 
	<input type="hidden" name="page" value="" />
	<input type="hidden" name="GS_CODE" value="${GS_CODE }" />
</form>